package synchronicity.ui;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;

import ui.DisplayContext;
import ui.Screen;

public class HomeScreen extends Screen {
	private static HomeScreen instance;

	private List mainMenu;

	private HomeScreen(DisplayContext context) {
		super(context);
		mainMenu = new List(null, Choice.IMPLICIT,
				new String[] { "Schedule a meeting with others", "Add an event to your calendar" }, new Image[] { null, null });
	}

	public static synchronized HomeScreen getInstance(DisplayContext context) {
		if (instance == null) {
			instance = new HomeScreen(context);
		}
		return instance;
	}

	protected Command[] getCommands() {
		return getDefaultCommands();
	}

	protected Displayable getDisplayable() {
		return mainMenu;
	}

	protected String getTitle() {
		return "Synchronicity";
	}

	public void commandAction(Command command, Displayable display) {
		if (display.equals(mainMenu) && command.equals(List.SELECT_COMMAND)) {
			switch (mainMenu.getSelectedIndex()) {
			case 0:
				switchScreen(ScheduleMeetingScreen.getInstance(getContext()));
				break;
			case 1:
				switchScreen(AddSingleEventScreen.getInstance(getContext()));
				break;
			default:
				break;
			}
		}
	}
}
